package com.xcity.game.combat.unit.impl;

import java.util.Arrays;

import com.xcity.db.entity.Player;
import com.xcity.game.combat.AbstractCombatUnit;
import com.xcity.game.combat.CombatTeam;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.skill.CombatSkillFactory;
import com.xcity.game.employee.Clazz;
import com.xcity.game.employee.EmployeeUtils;

/**
 * 玩家战斗时的unit
 * @author yang.li
 *
 */
public class PlayerCombatUnit extends AbstractCombatUnit<Player> {

	public PlayerCombatUnit(CombatTeam team, Player player) {
		super(team, player);
		setAttributeValue(CombatAttributeType.ATTACK_POWER, player.getAttackPower());
		setAttributeValue(CombatAttributeType.MAGIC_POWER, player.getMagicPower());
		setAttributeValue(CombatAttributeType.DEFENSE, player.getDefense());
		setAttributeValue(CombatAttributeType.MAGIC_DEFENSE, player.getMagicDefense());
		setAttributeValue(CombatAttributeType.CRIT, player.getCrit());
		setAttributeValue(CombatAttributeType.AVOID_CRIT, player.getAvoidCrit());
		setAttributeValue(CombatAttributeType.MAX_HP, player.getHp());
		setAttributeValue(CombatAttributeType.HP, player.getHp());
		setAttributeValue(CombatAttributeType.ATTACK_SPEED, player.getAttackSpeed());
		setAttributeValue(CombatAttributeType.DODGE, player.getDodge());
		setAttributeValue(CombatAttributeType.RESIST, player.getResist());
		setAttributeValue(CombatAttributeType.HIT_RATE, player.getHitRate());
		setAttributeValue(CombatAttributeType.MAGIC_HIT_RATE, player.getMagicHitRate());
//		setAttributeValue(CombatAttributeType.CRIT_DAMAGE, 0);
//		setAttributeValue(CombatAttributeType.MP, 0);
//		setAttributeValue(CombatAttributeType.MAX_MP, 0);
//		DefaultSkillV2 skill = player.getSkillManager() != null ? player.getSkillManager().getActive() : null;
//		if (skill != null) {
//			this.skills = new ArrayList<CombatSkill>(1);
//			CombatSkill cs = CombatSkillFactory.create(skill.getTemplate());
//			if (cs != null) {
//				this.skills.add(cs);
//			}
//		}
		if (player.getSkillManager() != null) {
			CombatSkill cs = CombatSkillFactory.create(player.getSkillManager().getActive());
			this.skills = Arrays.asList(cs);
			setAttributeValue(CombatAttributeType.MAX_MP, cs.getMp());
		}
	}

	@Override
	public int getQualityLvl() {
		return combatable.getQualityLvl();
	}

	@Override
	public Clazz getClazz() {
		return EmployeeUtils.getPlayerTemplate().getClazz();
	}
	
}
